package com.ds.dsfans.magicapi.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ds.dsfans.common.annotation.Log;
import com.ds.dsfans.common.enums.BusinessType;
import com.ds.dsfans.magicapi.domain.MagicApiFileBackup;
import com.ds.dsfans.magicapi.service.IMagicApiFileBackupService;
import com.ds.dsfans.common.core.controller.BaseController;
import com.ds.dsfans.common.core.domain.AjaxResult;
import com.ds.dsfans.common.utils.poi.ExcelUtil;
import com.ds.dsfans.common.core.page.TableDataInfo;

/**
 * 脚本备份Controller
 * 
 * @author dsfans
 * @date 2024-07-11
 */
@Controller
@RequestMapping("/magicapi/MagicAPIBackup")
public class MagicApiFileBackupController extends BaseController
{
    private String prefix = "magicapi/MagicAPIBackup";

    @Autowired
    private IMagicApiFileBackupService magicApiFileBackupService;

    @RequiresPermissions("magicapi:MagicAPIBackup:view")
    @GetMapping()
    public String MagicAPIBackup()
    {
        return prefix + "/MagicAPIBackup";
    }

    /**
     * 查询脚本备份列表
     */
    @RequiresPermissions("magicapi:MagicAPIBackup:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MagicApiFileBackup magicApiFileBackup)
    {
        startPage();
        List<MagicApiFileBackup> list = magicApiFileBackupService.selectMagicApiFileBackupList(magicApiFileBackup);
        return getDataTable(list);
    }

    /**
     * 导出脚本备份列表
     */
    @RequiresPermissions("magicapi:MagicAPIBackup:export")
    @Log(title = "脚本备份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MagicApiFileBackup magicApiFileBackup)
    {
        List<MagicApiFileBackup> list = magicApiFileBackupService.selectMagicApiFileBackupList(magicApiFileBackup);
        ExcelUtil<MagicApiFileBackup> util = new ExcelUtil<MagicApiFileBackup>(MagicApiFileBackup.class);
        return util.exportExcel(list, "脚本备份数据");
    }

    /**
     * 新增脚本备份
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存脚本备份
     */
    @RequiresPermissions("magicapi:MagicAPIBackup:add")
    @Log(title = "脚本备份", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MagicApiFileBackup magicApiFileBackup)
    {
        return toAjax(magicApiFileBackupService.insertMagicApiFileBackup(magicApiFileBackup));
    }

    /**
     * 修改脚本备份
     */
    @RequiresPermissions("magicapi:MagicAPIBackup:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MagicApiFileBackup magicApiFileBackup = magicApiFileBackupService.selectMagicApiFileBackupById(id);
        mmap.put("magicApiFileBackup", magicApiFileBackup);
        return prefix + "/edit";
    }

    /**
     * 修改保存脚本备份
     */
    @RequiresPermissions("magicapi:MagicAPIBackup:edit")
    @Log(title = "脚本备份", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MagicApiFileBackup magicApiFileBackup)
    {
        return toAjax(magicApiFileBackupService.updateMagicApiFileBackup(magicApiFileBackup));
    }

    /**
     * 删除脚本备份
     */
    @RequiresPermissions("magicapi:MagicAPIBackup:remove")
    @Log(title = "脚本备份", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(magicApiFileBackupService.deleteMagicApiFileBackupByIds(ids));
    }
}
